package thread;

/**
 * 当一个线程调用sleep方法处于睡眠阻塞的过程中若该线程的interrupt方法调用，则会打断其睡眠阻塞状态，
 * 此时sleep方法会抛出中断异常，InterruptedException
 */
public class SleepDemo2 {
    public static void main(String[] args) {
        Thread lin = new Thread() {
          public void run() {
              System.out.println(getName()+":刚美完容，睡一会儿吧....");
              try {
                  Thread.sleep(50000);
              } catch (InterruptedException e) {
                  System.out.println(getName()+":干嘛呢！");
              }
              System.out.println(getName()+"醒了");
          }
        };

        Thread wang = new Thread() {
            public void run() {
                System.out.println(getName()+"大锤八十，小锤四十");
                for (int i = 0; i < 5; i++) {
                    System.out.println(getName()+"八十！");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                    }
                }
                lin.interrupt();//中断lin的睡眠阻塞
            }
        };
        lin.start();
        wang.start();
    }
}
